gint pixel_size)
{
GtkIconTheme *icon_theme;
- const char *separator;
- GString *icon_name;
+ char *content_type;
+ GIcon *icon;
+ GtkIconInfo *info;
GdkPixbuf *pixbuf;
- separator = strchr (mime_type, '/');
- if (!separator)
- return NULL;
-
icon_theme = gtk_icon_theme_get_default ();
- /* try with the three icon name variants for MIME types */
-
- /* canonicalize MIME type: foo/x-bar -> foo-x-bar */
- icon_name = g_string_new (NULL);
- g_string_append_len (icon_name, mime_type, separator - mime_type);
- g_string_append_c (icon_name, '-');
- g_string_append (icon_name, separator + 1);
- pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
- pixel_size,
- 0,
- NULL);
- g_string_free (icon_name, TRUE);
- if (pixbuf)
- return pixbuf;
-
- /* canonicalize MIME type, and prepend "gnome-mime-" */
- icon_name = g_string_new ("gnome-mime-");
- g_string_append_len (icon_name, mime_type, separator - mime_type);
- g_string_append_c (icon_name, '-');
- g_string_append (icon_name, separator + 1);
- pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
- pixel_size,
- 0,
- NULL);
- g_string_free (icon_name, TRUE);
- if (pixbuf)
- return pixbuf;
-
- /* try the MIME family icon */
- icon_name = g_string_new ("gnome-mime-");
- g_string_append_len (icon_name, mime_type, separator - mime_type);
- pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
- pixel_size,
- 0,
- NULL);
- g_string_free (icon_name, TRUE);
+ content_type = g_content_type_from_mime_type (mime_type);
+ icon = g_content_type_get_icon (content_type);
+ info = gtk_icon_theme_lookup_by_gicon (icon_theme,
+ icon,
+ pixel_size,
+ GTK_ICON_LOOKUP_USE_BUILTIN);
+ pixbuf = gtk_icon_info_load_icon (info, NULL);
+
+ g_free (content_type);
+ g_object_unref (icon);
+ gtk_icon_info_free (info);
return pixbuf;
}